orderService.$inject = ['$http'];

function orderService($http) {

    return {
        addOrder:addOrder,
        findOrderByClient:findOrderByClient,
        findOrderByOid:findOrderByOid,
        findOrderByOstateandClient:findOrderByOstateandClient,
        updateOstateByOid:updateOstateByOid
    }

    function addOrder(neworder, callback) {

        $http.post("/cv4Backend/order/addOrder",neworder).then(function (res) {
            console.log(res.data);
            callback(null, res.data);
        }).catch(err => console.log(err));
    }

    function findOrderByClient(cid, callback) {
        $http.get("/cv4Backend/order/findOrderByClient/"+cid).then(function(res) {
            callback(null, res.data);
        }).catch(err => console.log(err));
    }

    function findOrderByOid(orderid, callback) {
        $http.get("/cv4Backend/order/findOrderByOid/"+orderid).then(function(res){
            callback(null, res.data);
        }).catch(err => console.log(err));
    }

    function findOrderByOstateandClient(cid, ostate, callback) {
        $http.get("/cv4Backend/order/findOrderByOstateandClient/"+cid+"/"+ostate).then(function(res) {
            callback(null, res.data);
        }).catch(err => console.log(err));
    }

    function updateOstateByOid(orderid, ostate, callback) {
        console.log('updateOstateByOid in service come in');
        $http.get("/cv4Backend/order/updateOstateByOid/"+orderid+"/"+ostate).then(function(res) {
            console.log(res.data);
            callback(null, res.data);
        }).catch(err => console.log(err));
    }
    
}

module.exports = orderService;
